extends CharacterBody2D

@export var speed = 100.0
var inputVec:Vector2
@onready var vJoysticks:VirtualJoysticks02 = $"../VirtualJoysticks02"
@onready var weapon01:WeaponBase = $Weapon01


func _ready():
	add_to_group("Player")
	Global.signalPlayerHit.connect(onHit)
	
	vJoysticks.sOnInput.connect(onInput)
	weapon01.startShoot()
	

func _exit_tree():
	Global.signalPlayerHit.disconnect(onHit)
	
	vJoysticks.sOnInput.disconnect(onInput)
	weapon01.endShoot()


func _physics_process(delta):
	velocity = inputVec * speed
	move_and_slide()
	

func onInput(ipt):
	inputVec = ipt
	

func onHit():
	queue_free()
	Global.signalGameEnd.emit(false)
